#include "stdafx.h"
#include "vehicles.h"

Vehicles::Vehicles()
{
}

void Vehicles::addVehicle(string lRegNum, string lMake, string lModel, bool lInRent, int lAge, bool lAutoGearbox,
	double lStorageSpace, double lWeightAllowance, double lVehicleHeight)
{
	vans.push_back(Van(lRegNum,lMake,lModel,lInRent,lAge,lAutoGearbox,lStorageSpace,lWeightAllowance,lVehicleHeight));
}

void Vehicles::addVehicle(string lRegNum, string lMake, string lModel, bool lInRent, int lAge, bool lAutoGearbox,
	int lNumSeats, int lNumDoors)
{
	cars.push_back(Car(lRegNum,lMake,lModel,lInRent,lAge,lAutoGearbox,lNumSeats,lNumDoors));
}

void Vehicles::deleteVan(string lRegNum)
{
	unsigned int i;

	for(i=0;i<vans.size();i++)
		if(vans[i].getRegNum()==lRegNum)
		{
			vans.erase(vans.begin()+i);
			return;
		}
}

void Vehicles::deleteCar(string lRegNum)
{
	unsigned int i;

	for(i=0;i<cars.size();i++)
		if(cars[i].getRegNum()==lRegNum)
		{
			cars.erase(cars.begin()+i);
			return;
		}
}

void Vehicles::deleteVehicle(string lRegNum)
{
	if(getVehicleType(lRegNum)==CAR)
		deleteCar(lRegNum);
	else
	if(getVehicleType(lRegNum)==VAN)
		deleteVan(lRegNum);
}

int Vehicles::totalVehicleAmount()
{
	return (int)(cars.size()+vans.size());
}

int Vehicles::getVehicleType(string lRegNum)
{
	Car *car;
	Van *van;

	car=getCar(lRegNum);
	if(car!=NULL)
		return car->getVehicleType();

	van=getVan(lRegNum);
	if(van!=NULL)
		return van->getVehicleType();

	return 0;
}

Car *Vehicles::getCar(string lRegNum)
{
	unsigned int i;

	for(i=0;i<cars.size();i++)
		if(cars[i].getRegNum()==lRegNum)
			return &cars[i];

	return NULL;
}

Van *Vehicles::getVan(string lRegNum)
{
	unsigned int i;

	for(i=0;i<vans.size();i++)
		if(vans[i].getRegNum()==lRegNum)
			return &vans[i];

	return NULL;
}
